﻿/*
 * Created by SharpDevelop.
 * User: IEscarro
 * Date: 9/1/2009
 * Time: 11:37 AM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using NHibernate;
using System.Collections.Generic;
using System.Data;
using Buaya.Model.Dao.Interface;

namespace Buaya.Model.Dao.NHibernate
{
	/// <summary>
	/// Description of NHibernateToDoDao.
	/// </summary>
	public class NHibernateToDoDao : IToDoDao
	{
		public NHibernateToDoDao()
		{
		}
		
		public void SaveOrUpdate(ToDo todo)
		{
			ISession session = NHibernateHelper.OpenSession();
			session.SaveOrUpdate(todo);
			session.Flush();
		}
		
		public void Delete(ToDo todo)
		{
			ISession session = NHibernateHelper.OpenSession();
			session.Delete(todo);
			session.Flush();
		}
		
		public ToDo ReadByPk(int id)
		{
			return NHibernateHelper.OpenSession().Load<ToDo>(id);
		}
		
		public IList<ToDo> FindAll()
		{
			return NHibernateHelper.OpenSession().CreateCriteria(typeof(ToDo)).List<ToDo>();
		}
	}
}
